class_name EffectUtil

static func plus_attr(multi: Multi, target: int, type: String, value):
	if not type:
		type = "value"
	var m = multi.get(target)
	set_value(m, type, value)


const SPLIT = "."


static func set_value(object, path: String, value):
	var i = path.find(SPLIT)
	var j = 0
	var old
	var k
	while i > j:
		var key = path.substr(j, i)
		old = object.get(key)
		if not old:
			object[key] = {}
		object = old
		j = i + 1
		i = path.find(SPLIT, j)
	if j > 0:
		path = path.substr(j, path.length())
	k = path
	old = object.get(k)
	object[k] = value
	return old


static func get_value(object, path: String):
	var i = path.find(SPLIT)
	var j = 0
	while i > j:
		var key = path.substr(j, i)
		var v = object.get(key)


static func next_int(start, end) -> int:
	return randi() % end + start


static func get_buff_value(value, default = 0):
	if not value:
		return default
	return value

# var t1 = EffectUtil.get_buff_value([])
# var t2 = EffectUtil.get_buff_value(false)
# var t3 = EffectUtil.get_buff_value(true)
# var t4 = EffectUtil.get_buff_value([1])
# var t5 = EffectUtil.get_buff_value(2)
# var t6 = EffectUtil.get_buff_value("")
# var t7 = EffectUtil.get_buff_value("a")
# print(t1, t2, t3, t4, t5, t6, t7)
#0 0 True [1] 2 0 a
